using System;
using System.Linq;
using System.Linq.Expressions;

using BLToolkit.Data.Linq;

using JetBrains.Annotations;

using Rsdn.Janus.DataModel;

namespace Rsdn.Janus
{
	public static class FavoritesHelper
	{
        public static Table<IFavoritesFolderTable> FavoriteFolders([NotNull] this IDataContext db)
		{
			if (db == null) throw new ArgumentNullException("db");
            return db.GetTable<IFavoritesFolderTable>();
		}

        public static IQueryable<IFavoritesFolderTable> FavoriteFolders(
			[NotNull] this IDataContext db,
            [CanBeNull] Expression<Func<IFavoritesFolderTable, bool>> predicate)
		{
			return db.GetTable(predicate);
		}

        public static IValueInsertable<IFavoritesFolderTable> IntoFavoriteFolders([NotNull] this IDataContext db)
		{
			if (db == null) throw new ArgumentNullException("db");
			return db.Into(db.FavoriteFolders());
		}

		public static Table<IFavoritesItemTable> FavoriteItems([NotNull] this IDataContext dbMgr)
		{
			if (dbMgr == null) throw new ArgumentNullException("dbMgr");
			return dbMgr.GetTable<IFavoritesItemTable>();
		}

		public static IQueryable<IFavoritesItemTable> FavoriteItems(
			[NotNull] this IDataContext dbMgr,
			[CanBeNull] Expression<Func<IFavoritesItemTable, bool>> predicate)
		{
			return dbMgr.GetTable(predicate);
		}

		public static IValueInsertable<IFavoritesItemTable> IntoFavoriteItems(
			[NotNull] this IDataContext db)
		{
			if (db == null) throw new ArgumentNullException("db");
			return db.Into(db.FavoriteItems());
		}
	}
}